package cn.iocoder.yudao.module.bpm.dal.mysql.sourcecatalog;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.bpm.controller.admin.sourcecatalog.vo.SourceCatalogPageReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.sourcecatalog.SourceCatalogDO;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;

/**
 * 资源编目 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface SourceCatalogMapper extends BaseMapperX<SourceCatalogDO> {

    default PageResult<SourceCatalogDO> selectPage(SourceCatalogPageReqVO reqVO) {

        LambdaQueryWrapperX query = null;

        if(StringUtils.isNotEmpty(reqVO.getSourceTypes())){
            if( reqVO.getSourceTypes().equals("1")){
                query = new LambdaQueryWrapperX<SourceCatalogDO>()
                        .eqIfPresent(SourceCatalogDO::getSourceId, reqVO.getSourceId())
                        .likeIfPresent(SourceCatalogDO::getAuthorName, reqVO.getAuthorName())
                        .likeIfPresent(SourceCatalogDO::getContributeName, reqVO.getContributeName())
                        .eqIfPresent(SourceCatalogDO::getAuthorDesc, reqVO.getAuthorDesc())
                        .eqIfPresent(SourceCatalogDO::getCatalogTags, reqVO.getCatalogTags())
                        .inIfPresent(SourceCatalogDO::getStatus,-1,1,3,4)
                        .eqIfPresent(SourceCatalogDO::getCatalogClassify, reqVO.getCatalogClassify())
                        .eqIfPresent(SourceCatalogDO::getCatalogDesc, reqVO.getCatalogDesc())
                        .eqIfPresent(SourceCatalogDO::getCatalogStore, reqVO.getCatalogStore())
                        .eqIfPresent(SourceCatalogDO::getWebUrl, reqVO.getWebUrl())
                        .eqIfPresent(SourceCatalogDO::getAttach, reqVO.getAttach())
                        .eqIfPresent(SourceCatalogDO::getLookUp, reqVO.getLookUp())
                        .eqIfPresent(SourceCatalogDO::getBizDelected, 0)
                        .betweenIfPresent(SourceCatalogDO::getCreateTime, reqVO.getCreateTime())
                        .orderByDesc(SourceCatalogDO::getId);
            }else if(reqVO.getSourceTypes().equals("2")){
                query = new LambdaQueryWrapperX<SourceCatalogDO>()
                        .eqIfPresent(SourceCatalogDO::getSourceId, reqVO.getSourceId())
                        .likeIfPresent(SourceCatalogDO::getAuthorName, reqVO.getAuthorName())
                        .likeIfPresent(SourceCatalogDO::getContributeName, reqVO.getContributeName())
                        .eqIfPresent(SourceCatalogDO::getAuthorDesc, reqVO.getAuthorDesc())
                        .eqIfPresent(SourceCatalogDO::getCatalogTags, reqVO.getCatalogTags())
                        .inIfPresent(SourceCatalogDO::getStatus,2)
                        .eqIfPresent(SourceCatalogDO::getCatalogClassify, reqVO.getCatalogClassify())
                        .eqIfPresent(SourceCatalogDO::getCatalogDesc, reqVO.getCatalogDesc())
                        .eqIfPresent(SourceCatalogDO::getCatalogStore, reqVO.getCatalogStore())
                        .eqIfPresent(SourceCatalogDO::getWebUrl, reqVO.getWebUrl())
                        .eqIfPresent(SourceCatalogDO::getAttach, reqVO.getAttach())
                        .eqIfPresent(SourceCatalogDO::getLookUp, reqVO.getLookUp())
                        .eqIfPresent(SourceCatalogDO::getBizDelected, 0)
                        .betweenIfPresent(SourceCatalogDO::getCreateTime, reqVO.getCreateTime())
                        .orderByDesc(SourceCatalogDO::getId);
            } else if(reqVO.getSourceTypes().equals("3")){
                query = new LambdaQueryWrapperX<SourceCatalogDO>()
                        .eqIfPresent(SourceCatalogDO::getSourceId, reqVO.getSourceId())
                        .likeIfPresent(SourceCatalogDO::getAuthorName, reqVO.getAuthorName())
                        .likeIfPresent(SourceCatalogDO::getContributeName, reqVO.getContributeName())
                        .eqIfPresent(SourceCatalogDO::getAuthorDesc, reqVO.getAuthorDesc())
                        .eqIfPresent(SourceCatalogDO::getCatalogTags, reqVO.getCatalogTags())
                        .eqIfPresent(SourceCatalogDO::getCatalogClassify, reqVO.getCatalogClassify())
                        .eqIfPresent(SourceCatalogDO::getCatalogDesc, reqVO.getCatalogDesc())
                        .eqIfPresent(SourceCatalogDO::getCatalogStore, reqVO.getCatalogStore())
                        .eqIfPresent(SourceCatalogDO::getWebUrl, reqVO.getWebUrl())
                        .eqIfPresent(SourceCatalogDO::getAttach, reqVO.getAttach())
                        .eqIfPresent(SourceCatalogDO::getLookUp, reqVO.getLookUp())
                        .eqIfPresent(SourceCatalogDO::getBizDelected, 1)
                        .betweenIfPresent(SourceCatalogDO::getCreateTime, reqVO.getCreateTime())
                        .orderByDesc(SourceCatalogDO::getId);
            }
        }else{
            query = new LambdaQueryWrapperX<SourceCatalogDO>()
                    .eqIfPresent(SourceCatalogDO::getSourceId, reqVO.getSourceId())
                    .likeIfPresent(SourceCatalogDO::getAuthorName, reqVO.getAuthorName())
                    .likeIfPresent(SourceCatalogDO::getContributeName, reqVO.getContributeName())
                    .eqIfPresent(SourceCatalogDO::getAuthorDesc, reqVO.getAuthorDesc())
                    .eqIfPresent(SourceCatalogDO::getCatalogTags, reqVO.getCatalogTags())
                    .eqIfPresent(SourceCatalogDO::getStatus,reqVO.getStatus())
                    .eqIfPresent(SourceCatalogDO::getCatalogClassify, reqVO.getCatalogClassify())
                    .eqIfPresent(SourceCatalogDO::getCatalogDesc, reqVO.getCatalogDesc())
                    .eqIfPresent(SourceCatalogDO::getCatalogStore, reqVO.getCatalogStore())
                    .eqIfPresent(SourceCatalogDO::getWebUrl, reqVO.getWebUrl())
                    .eqIfPresent(SourceCatalogDO::getAttach, reqVO.getAttach())
                    .eqIfPresent(SourceCatalogDO::getLookUp, reqVO.getLookUp())
                    .eqIfPresent(SourceCatalogDO::getBizDelected, 0)
                    .betweenIfPresent(SourceCatalogDO::getCreateTime, reqVO.getCreateTime())
                    .orderByDesc(SourceCatalogDO::getId);
        }
        return selectPage(reqVO, query);
    }

    void rebackSourceCatalog(SourceCatalogDO update);
}